<?php
/**
 * Created by Chongyi
 * Date: 2015/10/10 0010
 * Time: 下午 2:45
 */

// 前台路由
Route::group(['namespace' => 'Site'], function () {

// TODO news
    Route::controller('news', 'IndustryInfoController',
        [
            'getIndex'   => 'industry',
            'getList'    => 'industry.lister',
            'getDetails' => 'industry.details',
            'getComm'    => 'industry.comm',
        ]);

    //忘记密码
    Route::controller('forgot-password', 'ForgotPasswordController',
        [
            'getIndex' => 'forgot-password',

        ]);
    //搜索
    Route::controller('search', 'SearchResultController',
        [
            'postIndex' => 'search',
        ]);

//供应报盘
    Route::controller('provider', 'ProviderController',
        [
            'getList'   => 'provider.list',
            'getInfo'   => 'provider.info',
            'postSave'  => 'provider.save',
            'getChoose' => 'provider.choose',
        ]);
// 采购询盘
    Route::controller('purchaser', 'PurchaserController',
        [
            'getList'        => 'purchaser.list',
            'getInfo'        => 'purchaser.info',
            'postSave'       => 'purchaser.save',
            'getChoose'      => 'purchaser.choose',
            'getHotShop'     => 'purchaser.hot-shop',
            'getGroomSupply' => 'purchaser.groom-supply',
        ]);
// 自由集散
    Route::controller('free', 'FreeController',
        ['getList' => 'free.list', 'getGoods' => 'free.goods', 'getChoose' => 'free.choose']);
// 供采分销
    Route::controller('distribution', 'DistributionController',
        [
            'getList'   => 'distribution.list',
            'getGoods'  => 'distribution.goods',
            'getChoose' => 'distribution.choose',

        ]);
// 商家中心
    Route::controller('merchant', 'MerchantController',
        [
            'getIndex' => 'merchant.index',
            'getInfo'  => 'merchant.supply-info',
        ]);
//
    Route::controller('financial', 'FinancialController',
        ['getIndex' => 'financial.index']);

    Route::controller('logistics', 'LogisticsController',
        ['getIndex' => 'logistics.index']);

// 店铺的相关信息
    Route::get('store/info', 'StoreController@getInfo');
    Route::get('store/product-list', 'StoreController@getProductList');
    Route::get('store/category-list', 'StoreController@getStoreCategory');
    Route::controller('store/{id}', 'StoreController',
        [
            'getAuthorizationRequest' => 'store.authorization',
            'getIndex'                => 'store',
            'getCompany'              => 'store.introduce',
            'getInfo'                 => 'store.supply-info',
            'getProduct'              => 'store.product',
            'getCanvass'              => 'store.canvass',
            'getCategory'             => 'store.category',

        ]);
    // 商品

    Route::get('goods/{id}', ['as' => 'goods.detail', 'uses' => 'GoodsController@index'])->where('id', '[0-9]+');
    //商品咨询
    Route::post('goods/consult', 'GoodsController@consult');
    Route::get('goods/detail', 'GoodsController@detail');

    Route::get('goods/{id}/comment', ['as' => 'goods.comments', 'uses' => 'GoodsController@comment'])->where('id',
        '[0-9]+');

    // ShoppingCarts
    Route::controller('cart', 'ShoppingCartController',
        [
            'postShoppingCart' => 'cart.shopping-cart',
            'getCartList'      => 'cart.cart-list',
        ]);

    //购物车中的数量增加--单个
    Route::put('cart/update-info', 'ShoppingCartController@putUpdateInfo');
    //购物车中的数量增加--随意
    Route::put('cart/change-info', 'ShoppingCartController@putChangeCount');
    //删除购物车中的数据
    Route::delete('cart/cart-info', 'ShoppingCartController@deleteCartInfo');
    //删除收货地址信息
    Route::delete('order/delete-addr', 'OrderShoppingController@deleteAddr');
    //删除发票信息
    Route::delete('order/delete-invoice', 'OrderShoppingController@deleteInvoiceInfo');
    //物流 帮我找车
    Route::post('help/find-truck', 'LogisticsServerController@postFindTruck');

    Route::controller('order', 'OrderShoppingController',
        [
            'postReceiptInformation' => 'order.receipt-info',
            'postSaveInvoice'        => 'order.add-invoice-info',
            'postCreateOrder'        => 'order.create-order',
            'postShoppingOrder'      => 'order.shopping-order',
            'getInfo'                => 'order.info',
            'getIndex'               => 'order',
            'getInvoice'             => 'order.invoice',
            'getSureOder'            => 'order.sure',
            'getInvoiceInfo'         => 'order.invoice-info',
            'getShopList'            => 'order.shop-list',
        ]);
    Route::controller('test', 'TestController', [
        'getIndex' => 'test',
    ]);


    Route::controller('register', 'Custom\MemberRegisterController',
        [
            'getPurchaser'  => 'register.purchaser',
            'getProvider'   => 'register.provider',
            'postPurchaser' => 'register.purchaser',
            'postProvider'  => 'register.provider',
        ]);

    Route::controller('passport', 'AuthController', ['getLogin' => 'custom.login', 'getLogout' => 'custom.logout']);

    Route::group(['middleware' => 'auth'], function () {

        Route::resource('account/member/store', 'Custom\Provider\StoreController',
            ['names' => ['index' => 'account.store']]);
        // 商品分类
        Route::get('account/member/category/information', 'Custom\Provider\CategoryController@information');
        Route::put('account/member/category/update', 'Custom\Provider\CategoryController@forceUpdate');
        Route::delete('account/member/category', 'Custom\Provider\CategoryController@delete');
        Route::resource('account/member/category', 'Custom\Provider\CategoryController',
            ['names' => ['index' => 'account.category.index', 'update' => 'account.category.update']]);

        // 商品规格
        Route::controller('account/member/goods-spec', 'Custom\Provider\GoodsSpecController');
        // 发布供应商品
        Route::delete('account/member/goods', 'Custom\Provider\GoodsController@destroy');
        Route::resource('account/member/goods', 'Custom\Provider\GoodsController',
            [
                'names' => [
                    'index'   => 'account.goods.index',
                    'create'  => 'account.goods.create',
                    'update'  => 'account.goods.update',
                    'edit'    => 'account.goods.edit',
                    'destroy' => 'account.goods.delete',
                ],
            ]);

        // 供应商-价格策略-删除
        Route::delete('account/member/price-strategy/destroy',
            [
                'uses' => 'Custom\Provider\PriceStrategyController@destroy',
                'as'   => 'account.member.price-strategy.destroy',
            ]);

        // 供应商-价格策略-编辑的页面
        Route::get('account/member/price-strategy/edit',
            [
                'uses' => 'Custom\Provider\PriceStrategyController@edit',
                'as'   => 'account.member.price-strategy.edit',
            ]);

        // 供应商-价格策略-修改
        Route::post('account/member/price-strategy/update',
            [
                'uses' => 'Custom\Provider\PriceStrategyController@update',
                'as'   => 'account.member.price-strategy.update',
            ]);

        // 供应商-价格策略-添加
        Route::post('account/member/price-strategy/store',
            [
                'uses' => 'Custom\Provider\PriceStrategyController@store',
                'as'   => 'account.member.price-strategy.store',
            ]);

        // 供应商-价格策略-首页
        Route::controller('account/member/price-strategy', 'Custom\Provider\PriceStrategyController',
            ['getIndex' => 'account.price-strategy.index']);

        Route::put('account/member/offer/cancel', 'Custom\Provider\OfferController@cancel');
        //  发布供应报盘
        Route::resource('account/member/offer', 'Custom\Provider\OfferController',
            [
                'names' => [
                    'create' => 'account.offer.create',
                    'index'  => 'account.offer.index',
                    'edit'   => 'account.offer.edit',
                    'update' => 'account.offer.update',
                ],
            ]);

        // 采购询盘
        Route::put('account/member/enquiry',
            ['uses' => 'Custom\Purchaser\EnquiryController@cancel', 'as' => 'account.enquiry.cancel']);
        Route::resource('account/member/enquiry', 'Custom\Purchaser\EnquiryController',
            [
                'names' => [
                    'index'   => 'account.enquiry.index',
                    'create'  => 'account.enquiry.create',
                    'update'  => 'account.enquiry.update',
                    'edit'    => 'account.enquiry.edit',
                    'destroy' => 'account.enquiry.delete',
                ],
            ]);
        // 采购商地址
        Route::delete('account/member/address', 'Custom\Purchaser\AddressController@destroy');
        Route::resource('account/member/address', 'Custom\Purchaser\AddressController',
            [
                'names' => [
                    'index'   => 'account.address.index',
                    'create'  => 'account.address.create',
                    'update'  => 'account.address.update',
                    'edit'    => 'account.address.edit',
                    'destroy' => 'account.address.delete',
                ],
            ]);

        // 采购商 - 我的供应商
        Route::controller('account/member/my-provider', 'Custom\Purchaser\MyProviderController',
            ['getIndex' => 'account.my-provider.index']);

        // 采购商-采购意向单-删除
        Route::delete('account/member/counter-enquiry/cancel',
            [
                'uses' => 'Custom\Purchaser\CounterEnquiryController@cancel',
                'as'   => 'account.counter-enquiry.cancel',
            ]);

        // 采购商-采购意向单-处理(调用必须在account/member/counter-enquiry这个路由之前)
        Route::put('account/member/counter-enquiry/status',
            [
                'uses' => 'Custom\Purchaser\CounterEnquiryController@status',
                'as'   => 'account.counter-enquiry.status',
            ]);

        // 采购商-采购意向单
        Route::resource('account/member/counter-enquiry', 'Custom\Purchaser\CounterEnquiryController',
            [
                'names' => [
                    'index' => 'account.counter-enquiry.index',
                ],
            ]);

        // 采购商 - 订单
        Route::get('account/purchaser/order/{id}/detail',
            ['uses' => 'Custom\Purchaser\OrderController@getDetail', 'as' => 'account.purchaser.order.detail']);
        Route::controller('account/purchaser/order', 'Custom\Purchaser\OrderController',
            ['getIndex' => 'account.purchaser.order.index']);

        // 采购商-我的申请
        Route::controller('account/purchaser/my-authorization-request',
            'Custom\Purchaser\MyAuthorizationRequestController',
            ['getIndex' => 'account.purchaser.my-authorization-request.index']);

        // 采购商-我的商品
        Route::controller('account/purchaser/my-goods', 'Custom\Purchaser\MyGoodsController',
            ['getIndex' => 'account.my-goods.index']);

        // 采购商-退换货管理
        Route::controller('account/purchaser/return-management', 'Custom\Purchaser\ReturnManagementController',
            ['getIndex' => 'account.purchaser.return-management.index']);

        // 采购商 - 我的咨询
        Route::controller('account/purchaser/my-issue', 'Custom\Purchaser\MyIssueController',
            ['getIndex' => 'account.my-issue.index']);

        // 采购商 - 发票管理
        Route::controller('account/purchaser/invoice-management', 'Custom\Purchaser\InvoiceManagementController',
            ['getIndex' => 'account.invoice-management.index']);

        // 供应商-我的采购商
        Route::get('account/member/my-purchaser',
            ['uses' => 'Custom\Provider\MyPurchaserController@index', 'as' => 'account.my-purchaser.index']);
        Route::put('account/member/my-purchaser/{id}/licensed-goods/{lid}', [
            'uses' => 'Custom\Provider\MyPurchaserController@putLicensedEdit',
            'as'   => 'account.my-purchaser.licensed.update',
        ]);
        Route::put('account/member/my-purchaser/shutdown', [
            'uses' => 'Custom\Provider\MyPurchaserController@putShutdown',
            'as'   => 'account.my-purchaser.shutdown',
        ]);
        Route::get('account/member/my-purchaser/{id}/licensed-goods/{lid}/edit',
            [
                'uses' => 'Custom\Provider\MyPurchaserController@getLicensedEdit',
                'as'   => 'account.my-purchaser.licensed.edit',
            ]);
        Route::controller('account/member/my-purchaser/{id}/licensed-goods', 'Custom\Provider\MyPurchaserController',
            ['getIndex' => 'account.my-purchaser.licensed']);

        // 供应商-采购商审批-同意
        Route::put('account/member/authorization-request/agree',
            [
                'uses' => 'Custom\Provider\AuthorizationRequestController@agree',
                'as'   => 'account.member.authorization.request.agree',
            ]);
        // 供应商-采购商审批-拒绝
        Route::put('account/member/authorization-request/refuse',
            [
                'uses' => 'Custom\Provider\AuthorizationRequestController@refuse',
                'as'   => 'account.member.authorization.request.refuse',
            ]);

        // 供应商-采购商审批-首页
        Route::get('account/member/authorization-request/{id}', [
            'uses' => 'Custom\Provider\AuthorizationRequestController@show',
            'as'   => 'account.member.authorization-request.show',
        ]);

        Route::resource('account/member/distribution-system-relationship',
            'Custom\Provider\DistributionSystemRelationshipController',
            ['names' => ['index' => 'account.distribution-system-relationship.index']]);

        Route::controller('account/member/authorization-request', 'Custom\Provider\AuthorizationRequestController',
            ['getIndex' => 'account.member.authorization.request.index']);

        // 供应商-还盘意向单-删除
        Route::delete('account/member/counter-offer/cancel',
            [
                'uses' => 'Custom\Provider\CounterOfferController@cancel',
                'as'   => 'account.counter-offer.cancel',
            ]);

        // 供应商-还盘意向单-处理
        Route::put('account/member/counter-offer/status',
            [
                'uses' => 'Custom\Provider\CounterOfferController@status',
                'as'   => 'account.counter-offer.status',
            ]);

        // 供应商-还盘意向单
        Route::resource('account/member/counter-offer', 'Custom\Provider\CounterOfferController',
            [
                'names' => [
                    'index' => 'account.counter-offer.index',
                ],
            ]);

        // 供应商订单
        Route::get('account/provider/order/{id}/detail',
            ['uses' => 'Custom\Provider\OrderController@getDetail', 'as' => 'account.provider.order.detail']);
        Route::controller('account/provider/order', 'Custom\Provider\OrderController',
            ['getIndex' => 'account.provider.order.index']);

        // 供应商 - 导航管理
        Route::controller('account/provider/store-navigation', 'Custom\Provider\StoreNavigationController',
            ['getIndex' => 'account.store-navigation.index']);

        // 供应商 - 退换货管理
        Route::controller('account/provider/return-management', 'Custom\Provider\ReturnManagementController',
            ['getIndex' => 'account.provider.return-management.index']);

        // 供应商 - 咨询管理
        Route::controller('account/provider/issue', 'Custom\Provider\IssueController',
            ['getIndex' => 'account.issue.index']);

        // 供应商 - 公司资料
        Route::put('account/provider/company/password', 'Custom\Provider\StoreController@password');
        Route::put('account/provider/company/email', 'Custom\Provider\StoreController@email');
        Route::resource('account/provider/company', 'Custom\Provider\StoreController',
            ['names' => ['index' => 'account.provider.company']]);

        // 采购商 - 公司资料
        Route::put('account/purchaser/company/password', 'Custom\Purchaser\CompanyInformationController@password');
        Route::put('account/purchaser/company/email', 'Custom\Purchaser\CompanyInformationController@email');
        Route::resource('account/purchaser/company', 'Custom\Purchaser\CompanyInformationController',
            ['names' => ['index' => 'account.purchaser.company']]);

        // 供应商 结算管理
        Route::controller('account/provider/settlement-management', 'Custom\Provider\SettlementManagementController', [
            'getIndex' => 'account.settlement-management.index',
        ]);

        // 用户中心【供应商 + 采购商】 短消息
        Route::controller('account/message', 'Custom\MessageController', ['getIndex' => 'account.message']);

        Route::controller('account/member/home', 'Custom\AccountHomeController', ['getIndex' => 'account.member.home']);
        Route::controller('/publish/upload', 'UploadController');
    });

    // 首页路由
    Route::get('/', [
        'as' => 'host',
        function () {
            $categories = \App\B2BProject\Site\ArticleCategory::getCategoryCollectionByCategoryName('helper');

            foreach ($categories->take(6)->get() as $category) {
                $data[] = [
                    'item_desc' => $category->display_name,
                    'item_list' => call_user_func_array(function ($articles, $category) {
                        $data = [];
                        foreach ($articles as $article) {
                            $data[] = [
                                'href_val' => route('industry.comm', ["$category->name", $article->id]),
                                'href_txt' => $article->title,
                            ];
                        }

                        return $data;
                    }, [$category->articles()->take(5)->get(), $category]),
                ];
            }
            view()->share('helpData', json_encode($data));

            //底部信息
            $bottomData = [];
            foreach (\App\B2BProject\Site\ArticleCategory::getArticleCollectionByCategoryName('dbxx')->get() as
                     $article) {
                $bottomData[] = [
                    'href_src'  => route('industry.comm', ["dbxx", $article->id]),
                    'href_text' => $article->title,
                ];
            }
            view()->share('bottomData', json_encode($bottomData));

            //热门关键字
            $heartData                 = [];
            $heartData['web_logo_img'] = \App\B2BProject\AttachmentPrivateFiles::where('id',
                \App\B2BProject\Custom\SiteSetting::where('id', 1)->first()->logo)->first()->adminRoute();
            $heartData['home_url']     = route('host');
            $heartData['d_code_img']   = "/assets/b2b/css/images/d-code.jpg";
            $heartData['csrfToken']    = csrf_token();

            foreach (\App\B2BProject\Custom\HotWord::orderBy('created_at',
                'desc')->take(5)->get() as $category) {
                $heartData['hot_words'][] = [
                    'href_val' => route('free.choose', ['cid' => $category->id, 'pid' => $category->parent_id]),
                    'word_txt' => $category->name,
                ];
            }
            view()->share('heartData', json_encode($heartData));

            return view('host/index');
        },
    ]);
});